package com.ruoyi.business.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.business.domain.OrderPaymentVoucher;
import com.ruoyi.business.domain.vo.OrderPaymentVoucherVo;
import com.ruoyi.common.core.mapper.BaseMapperPlus;

/**
 * 订单打款凭证Mapper接口
 *
 * @author ruoyi
 * @date 2024-04-24
 */
public interface OrderPaymentVoucherMapper extends BaseMapperPlus<OrderPaymentVoucherMapper, OrderPaymentVoucher, OrderPaymentVoucherVo> {


    /**
     * 根据订单id删除
     *
     * @param orderId
     * @return
     */
    default boolean deleteByOrderId(Long orderId) {
        return delete(new QueryWrapper<OrderPaymentVoucher>()
            .lambda()
            .eq(OrderPaymentVoucher::getOrderId, orderId)) > 0;
    }

    /**
     * 根据主表id查询
     *
     * @param masterId
     * @return
     */
    default OrderPaymentVoucherVo selectByMasterId(Long masterId) {
        return selectVoOne(new QueryWrapper<OrderPaymentVoucher>()
            .lambda()
            .eq(OrderPaymentVoucher::getOrderId, masterId)
            .last("limit 1"));
    }
}
